import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { CommonEntity } from '@/common/entities/base.entity';
// 引入新的 UPLOAD_STATUS 枚举
import { UPLOAD_STATUS, UPLOAD_STATUS_TYPE } from '@/common/enums';

@Entity({
  name: 'sys_files',
  comment: '文件',
})
export class Upload extends CommonEntity {
  @PrimaryGeneratedColumn({
    type: 'int',
    comment: '主键',
  })
  id: number;

  @Column({
    unique: true,
    comment: '文件唯一标识符',
    name: 'file_id',
  })
  fileId: string;

  @Column({
    comment: '文件原始名称',
    name: 'original_name',
  })
  originalName: string;

  @Column({
    comment: '存储的文件名（如上传后的文件名）',
    name: 'stored_name',
  })
  storedName: string;

  @Column('bigint', {
    comment: '文件总大小（字节）',
    name: 'file_size',
  })
  fileSize: number;


  @Column({
    type: 'varchar',
    comment: '上传路径',
    name: 'file_path',
  })
  filePath: string;

  @Column('bigint', {
    default: 0,
    comment: '已上传的文件大小（字节）',
    name: 'uploaded_size',
  })
  uploadedSize: number;

  @Column({
    comment: '文件分片的总数',
    name: 'total_chunks',
    default: 0,
  })
  totalChunks: number;

  @Column({
    default: 0,
    comment: '已上传的分片数量',
    name: 'uploaded_chunks',
  })
  uploadedChunks: number;

  @Column({
    type: 'enum',
    enum: UPLOAD_STATUS, // 使用新的 UPLOAD_STATUS 枚举
    default: UPLOAD_STATUS.PENDING,
    comment: '上传状态',
    name: 'status',
  })
  status: UPLOAD_STATUS_TYPE;
}
